package com.tql.mall.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tql.mall.common.result.R;
import com.tql.mall.model.product.SkuInfo;
import com.tql.mall.product.service.SkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: tyk
 * @Date: 2023/5/22 14:59
 * @Description:
 */
@RestController
@RequestMapping("admin/product/sku")
@Api(description = "Sku管理")
public class SkuController {


    @Autowired
    private SkuService skuService;

    /**
     * 获取sku列表
     */
    @GetMapping("skuList/{page}/{limit}")
    @ApiOperation("获取sku列表")
    public R<IPage<SkuInfo>> list(@PathVariable Long page, @PathVariable Long limit, Long shopId) {
        // 封装分页对象
        Page<SkuInfo> pageInfo = new Page<>(page, limit);
        // 查询
        IPage<SkuInfo> list = skuService.skuList(shopId, pageInfo);
        // 返回结果
        return R.ok(list);
    }


    /**
     * 保存SkuInfo
     */
    @PostMapping("saveSkuInfo")
    @ApiOperation("保存SkuInfo")
    public R<Void> saveSkuInfo(@RequestBody SkuInfo skuInfo) {
        skuService.saveSkuInfo(skuInfo);
        return R.ok();
    }


    /**
     * 商品上架
     */
    @GetMapping("onSale/{skuId}")
    @ApiOperation("商品上架")
    public R<Void> onSale(@PathVariable Long skuId) {
        skuService.onSale(skuId);
        return R.ok();
    }

    /**
     * 商品下架
     */
    @GetMapping("offSale/{skuId}")
    @ApiOperation("商品下架")
    public R<Void> offSale(@PathVariable Long skuId) {
        skuService.offSale(skuId);
        return R.ok();
    }
}
